﻿import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'security_logic.dart';
import '../../routes.dart';

/// 账号安全页面
class SecurityView extends GetView<SecurityLogic> {
  const SecurityView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: const Color(0xFF282528),
        elevation: 0,
        leading: GestureDetector(
          onTap: () => Get.back(),
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 20,
          ),
        ),
        title: const Text(
          '账号安全',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(24.w),
        child: Container(
          decoration: BoxDecoration(
            color: const Color(0xFF282528),
            borderRadius: BorderRadius.circular(28.r),
          ),
          child: Column(
            children: [
              Obx(() => _buildListItem('手机号', controller.phonenumber.value, () {})),
              _buildDivider(),
              Obx(() => _buildListItem('邮箱地址', 
                  controller.email.value.isEmpty ? '未绑定' : controller.email.value, () {})),
              _buildDivider(),
              _buildListItem('更改密码', '', () => Get.toNamed(SettingsRoutes.changePassword)),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildListItem(String title, String value, VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: 50.h,
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Row(
          children: [
            Text(
              title,
              style: TextStyle(
                color: Colors.white,
                fontSize: 16.sp,
              ),
            ),
            const Spacer(),
            if (value.isNotEmpty)
              Text(
                value,
                style: TextStyle(
                  color: const Color(0xFF666666),
                  fontSize: 14.sp,
                ),
              ),
            SizedBox(width: 8.w),
            const Icon(
              Icons.arrow_forward_ios,
              color: Color(0xFF666666),
              size: 16,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildDivider() {
    return Divider(
      height: 1,
      thickness: 1,
      color: const Color(0xFF1A1A1A),
      indent: 20.w,
      endIndent: 20.w,
    );
  }
}
